# -*- coding: UTF-8 -*-
# cython: language_level=3
import requests
from tqdm import tqdm

from db.mongodb import MongoDB
from utils.own_tools import get_host

db = MongoDB()
r = requests.post('http://1.119.14.218:22255/get_icp', json={'key': 'KJD%#&VCN437di&#h48', 'area': '蜀'},
                  timeout=(3, 100)).text
# print(r)
for i in tqdm(r.split(';')):
    if not i.startswith('http'):
        i = 'http://' + i
    try:
        host = get_host(i)
        home_page = host['home_page']
        host = host['host']
        print({'home_page': home_page, 'host': host, 'status': 0})
        db.add('todo_urls', {'home_page': home_page, 'host': host, 'status': 0})
    except:
        pass
